from time import sleep

import allure

from key_word.KeyWord import WebKeys
from locater.allPages import *
from selenium.webdriver.support import expected_conditions as EC

class CreateChapterLogic(WebKeys):
    """创建章节流程"""
    @allure.step("创建章节流程")
    def createChapter(self,chapter_name,chapter_content):
        with allure.step("流程代码路径：%s"%__file__):
            pass
        # 01 点击作家专区，打开新页签
        sleep(2)
        with allure.step("01 点击作家专区，打开新页签"):
            self.locator_with_wait(*page_index_author).click()

        # 等待新页签出现
        with allure.step("等待新页签出现"):
            self.wait.until(EC.number_of_windows_to_be(2))

        # 02 切换窗体
        with allure.step("切换窗体"):
            self.change_window(-1)

        # 03 点击章节管理按钮
        with allure.step("点击章节管理按钮"):
            self.locator_with_wait(*page_authorManage_chapterManagerBtn).click()

        # 等待新页签出现
        with allure.step("等待新页签出现"):
            self.wait.until(EC.number_of_windows_to_be(3))

        # 04 切换窗体
        with allure.step("切换窗体"):
            self.change_window(-1)

        # 05 点击新建章节
        with allure.step("点击新建章节"):
            self.locator_with_wait(*page_authorManage_createChapter).click()

        # 06 输入章节名、内容、选择收费
        # 输入章节名
        with allure.step("输入章节名"):
            self.locator_with_wait(*page_authorManage_createChapter_name).send_keys(chapter_name)
        # 输入章节内容
        with allure.step("输入章节内容"):
            self.locator_with_wait(*page_authorManage_createChapter_content).send_keys(chapter_content)
        # 滑动页面
        with allure.step("滑动页面"):
            self.scroll_to_element(*page_authorManage_createChapter_button)
        # 选择收费按钮
        with allure.step("选择收费按钮"):
            self.locator_with_wait(*page_authorManage_createChapter_nofee).click()
        # 点击提交按钮
        with allure.step("点击提交按钮"):
            self.locator_with_wait(*page_authorManage_createChapter_button).click()


